from datetime import datetime
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Float
from sqlalchemy.orm import relationship
from src.database import Base

# ... 其他模型 ...

class User(Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, index=True)
    username = Column(String, unique=True, index=True)
    email = Column(String, unique=True, index=True)
    password = Column(String)
    created_at = Column(DateTime, default=datetime.utcnow)

    # 关联关系
    favorites = relationship("Favorite", back_populates="user")
    orders = relationship("Order", back_populates="user")

class Spot(Base):
    __tablename__ = "spots"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String)
    description = Column(String)
    price = Column(Float)
    images = Column(String)
    type = Column(String)
    created_at = Column(DateTime, default=datetime.utcnow)

    # 关联关系
    favorites = relationship("Favorite", back_populates="spot")
    orders = relationship("Order", back_populates="spot")

class Favorite(Base):
    __tablename__ = "favorites"

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey("users.id"))
    spot_id = Column(Integer, ForeignKey("spots.id"))
    created_at = Column(DateTime, default=datetime.utcnow)

    # 关联关系
    user = relationship("User", back_populates="favorites")
    spot = relationship("Spot", back_populates="favorites")

class Order(Base):
    __tablename__ = "orders"

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey("users.id"))
    spot_id = Column(Integer, ForeignKey("spots.id"))
    quantity = Column(Integer)
    total_price = Column(Float)
    status = Column(String)
    visit_date = Column(DateTime)
    created_at = Column(DateTime, default=datetime.utcnow)

    # 关联关系
    user = relationship("User", back_populates="orders")
    spot = relationship("Spot", back_populates="orders") 